package com.javasm.mingming.login.phone;

import com.javasm.mingming.login.entity.LoginUserDetails;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author javasm
 * @version 0.1
 * @className PhoneToken
 * @descriptioin:
 * @date 2025/1/13 14:56
 * @since jdk11
 */
public class PhoneToken extends AbstractAuthenticationToken {

    private final Object principal;
    private String code;

    public PhoneToken(String phone,String code){
        super((Collection)null);
        this.principal = phone;
        this.code = code;
        this.setAuthenticated(false);
    }

    public PhoneToken(UserDetails userDetails) {
        super(userDetails.getAuthorities());
        this.principal = userDetails;
        this.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return this.code;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }
}
